package com.mldkhn.led_controller;

import com.larswerkman.colorpicker.ColorPicker;
import com.larswerkman.colorpicker.SaturationBar;
import com.larswerkman.colorpicker.ValueBar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Activity_Colorpicker extends Activity implements OnClickListener {

	private static ColorPicker picker;
	private static SaturationBar saturationBar;
	private static ValueBar valueBar;
	private static Button btnVielfarbeSetzen, btnVielfarbeLoeschen;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_colorpicker);
	    picker = (ColorPicker) findViewById(R.id.colorPickerVielfarbe);
	    saturationBar = (SaturationBar) findViewById(R.id.saturationBarVielfarbe);
	    valueBar = (ValueBar) findViewById(R.id.valueBarVielfarbe);
	    picker.addSaturationBar(saturationBar);
	    picker.addValueBar(valueBar);
	    btnVielfarbeSetzen = (Button) findViewById(R.id.btnVielfarbeSetzen);
	    btnVielfarbeSetzen.setOnClickListener(this);
	    btnVielfarbeLoeschen = (Button) findViewById(R.id.btnVielfarbeLoeschen);
	    btnVielfarbeLoeschen.setOnClickListener(this);
	    Bundle extras = getIntent().getExtras();
	    if(extras != null)
	    {
	    	picker.setColor(extras.getInt("Color"));
	    	picker.setOldCenterColor(extras.getInt("Color"));
	    }
	    
	    
	}

	@Override
	public void onClick(View v) {
		Intent intent = getIntent();
		switch(v.getId()){
		case R.id.btnVielfarbeSetzen:
			intent.putExtra("Color",picker.getColor());
			setResult(RESULT_OK, intent);
			finish();
			break;
		case R.id.btnVielfarbeLoeschen:
			intent.putExtra("Color",picker.getColor());
			setResult(3, intent);
			finish();
			break;
		}
		
	}
}
